home *** CD-ROM | disk | FTP | other *** search
- /*
- File: InterruptDisableLib.c
-
- Contains: Routines for disabling interrupts on 68K and PPC.
-
- Written by: Quinn "The Eskimo!"
-
- Copyright: © 1998 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
- */
-
- /////////////////////////////////////////////////////////////////////
- // Our prototypes
-
- #include <MixedMode.h>
-
- /////////////////////////////////////////////////////////////////////
- // Our prototypes
-
- #include "InterruptDisableLib.h"
-
- /////////////////////////////////////////////////////////////////////
- // Low-Level, Architecture-Specific, Subroutines
-
- #if GENERATINGPOWERPC
-
- // PowerPC Specific Code
-
- // On PPC, we use MixedMode to handle moving the PPC parameters
- // into the right 68K registers and back again. This make our
- // 68K very easy to write.
-
- enum {
- kGetSRProcInfo = kRegisterBased
- | RESULT_SIZE(SIZE_CODE(sizeof(UInt16)))
- | REGISTER_RESULT_LOCATION(kRegisterD0),
- kSetSRProcInfo = kRegisterBased
- | RESULT_SIZE(0)
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(UInt16)))
- };
-
- // We define the 68K as a statically initialised data structure.
- // The use of MixedMode to call these routines makes the routines
- // themselves very simple.
-
- static UInt16 gGetSR[] = {
- 0x40c0, // move sr,d0
- 0x4e75 // rts
- };
-
- static UInt16 gSetSR[] = {
- 0x46c0, // move d0,sr
- 0x4e75 // rts
- };
-
- static UInt16 GetSR(void)
- // Returns the current value of the SR, interrupt mask
- // and all! This routine uses MixedMode to call the gGetSR data
- // structure as if it was 68K code (which it is!).
-
- {
- return CallUniversalProc( (UniversalProcPtr) &gGetSR, kGetSRProcInfo);
- }
-
- static void SetSR(UInt16 newSR)
- // Returns the value of the SR, including the interrupt mask and all
- // the flag bits. This routine uses MixedMode to call the gGetSR data
- // structure as if it was 68K code (which it is!).
- {
- CallUniversalProc( (UniversalProcPtr) &gSetSR, kSetSRProcInfo, newSR);
- }
-
- #else
-
- // Classic 68K and CFM-68K Specific Code
-
- // On classic 68K (and CFM-68K) we can simply access the
- // 68K SR register using some inline procedures.
-
- static UInt16 GetSR(void) = {
- 0x40c0 // move sr,d0
- };
-
- #pragma parameter SetSR(__D0)
- static void SetSR(UInt16 newSR) = {
- 0x46c0 // move d0,sr
- };
-
- #endif
-
- /////////////////////////////////////////////////////////////////////
- // High-Level Entry Points
-
- extern pascal UInt16 GetInterruptMask(void)
- // See comment in header file.
- {
- return (GetSR() >> 8) & 7;
- }
-
- extern pascal UInt16 SetInterruptMask(UInt16 newMask)
- // See comment in header file.
- {
- UInt16 currentSR;
-
- currentSR = GetSR();
- SetSR( (currentSR & 0xF8FF) | (newMask << 8) );
-
- return (currentSR >> 8) & 7;
- }
-